Scripting Window
Introduction
The
Scripting Window provides you with a very general and powerful
interface to the program. It allows you to manipulate geometric objects,
materials, post effects, user interfaces or any other objects of the program.
This
tutorial demonstrates the basic ideas behind scripting. It also describes
the basic structure of the Realsoft 3D program.
Open
the scripting window by selecting the pull-down menu 'Windows/Scripting Window'.
Then set the 'Language' field to 'RPL' (or another language that has been
plugged in). This tutorial includes examples for RPL language.
Exploring the structure
of Realsoft 3D
The structure
of the Realsoft 3D application is hierarchical. The program consists of
several sub objects which all have their own internal sub structure.
To find
out the sub structure of Realsoft 3D application object, just enter the
command:
"" Attrs
This gives
you the list of all properties (attributes) defined by Realsoft 3D application
object.
object CurrentProject object ProjectList
object Filer object UnitConverte object RenderSettings object RenderOutputs object Macros ...
One of
the attributes defined by the Realsoft 3D application is 'CurrentProject'.
The type of 'CurrentProject' field is object which means that its internal
structure can be explored further by calling:
"CurrentProject" Attrs
This
shows you the sub structure of the "CurrentProject" object:
object UnitConverte bool AnimRecord object Geometrics object Materials object ImageEffects ...
The 'CurrentProject'
object in turn consists of several sub objects, such as geometric objects,
materials, image effects, an animator and so on.
To find
out what properties the 'Animator' object defines, enter the command:
"CurrentProject.Animator" Attrs
The command
prints out the following properties:
int Frame float Param int Field int Sample ...
and so on.
This way you can actually examine the complete data structure of the Realsoft
3D application and locate all the properties in it. This hierarchical structure
is well known from many file systems, where files and folders can be referred
using hierarhcial name path.
Reading and Changing Attributes
You can
change attributes of objects using the 'Set' command.
In
the previous chapter, we explored the structure of Realsoft 3D and found
that 'CurrentProject' owns an 'Animator' object, which defines a 'Time' attribute.
Let's
change the current animation time by entering the command:
1.0 "CurrentProject.Animator.Time" Set
This moves
the animation slider to 1.0 second (which corresponds to frame 25 or 30
depending on the video system).
If
you prefer frames instead of seconds, try:
30 "CurrentProject.Animator.Frame" Set
The time
slider moves to frame 30. Let's assume you want to activate field rendering.
The Animator defines an attribute 'FieldRendering" whose type is boolean.
In other words, field rendering option can either be on or off (1 or 0).
To activate field rendering, set value of 1 to this attribute:
1 "CurrentProject.Animator.FieldRendering" Set
and
field rendering control will appear in the animation controls allowing you
to control the current field.
All basic object attributes can be set this way.
You can fetch and print out the current time using the 'Get' command:
"CurrentProject.Animator.Time" Get F.
Geometric objects
are defined by 'CurrentProject.Geometrics' object. For example, to print
out the name of the root level, call:
"CurrentProject.Geometrics.Root.Name" Get .
or, to rename the root level, call:
"new root name" "CurrentProject.Geometrics.Root.Name" Set
Arrays
Many geometric
objects define variable arrays. For example, subdivision surfaces and nurbs
curves both define array attribute named 'Points'.
Let's imagine
you need to set the third point of a nurbs curve. This can be achieved
as follows:
0.1 0.2 0.0 1.0 "Points.2" Set
Note : nurbs curves
consists of four dimension points (x, y, z and weight).
Or, if
you want to change the X component of a point whose index is 10, call:
0.1 "Points.10.x" Set
Classes
Each object
in Realsoft 3D has a certain well-defined structure. For example, the type
of the 'CurrentProject' is 'object'. The type of the 'CurrentProject.Animator.Time'
is floating point value.
The 'Class' command can be used for fetching the information about a certain
attribute.
For example, the command
"" Class
shows
you information about the Realsoft 3D application class.
The command
"CurrentProject.Animator.Time" Class
prints
out 'float'. In other words, the class of the 'Time' attribute is 'double
precision floating point' (Realsoft 3D uses only double precision floating
points).
Current Object
Just
like DOS and Unix operating systems allow you to manage current directory
via 'cd' command, the scripting window allows you to manage 'current
object' via 'Co' command.
This command allows you to avoid typing overhead by making the object you
are working on the current object.
Let's assume you have created a sphere whose name is 'mysphere' and you want
to set several sphere specific attributes. To make the sphere the current
working object, enter:
"CurrentProject.Geometrics.Root.mysphere" Co
Then
you can enter any sphere specific attributes without specifying the object
name. For example, to set the sphere's 'Center' attribute to world origin:
0 0 0 "Center" Set
Or,
to rename the object, call:
"moon" Name Set
If you get lost in the object hierarchy, you can use "PrintCo" command. It
prints out the current working object.
All commands that deal with object names obey the current working object.
For example, if you now enter the command
"" Attrs
You will actually see sphere's attributes rather than the attributes of the
application object.
Just like Unix and DOS operating systems allow you to define absolute file
names by starting the file names with slash (or back slash), Scripting window
allows you to start object names with dot (.). For example, to move back
to the application object (the highest possible hierarchy level), enter:
." Co
Or, to move to say CurrentProject object, enter:
".CurrentProject" Co
Another frequently needed operation is to move upwards in the object hierarchy.
This can be done by entering the command
Up
There are also commands 'Next' and 'Prev' for selecting the next and the
previous objects.
Deleting and Moving Objects
Realsoft 3D scripting system allows you to move and copy objects the same
way as you can move and copy files in disk operating systems.
You can use 'Copy' command to copy an object. For example:
"sphere1" "sphere2" Copy
The created 'sphere2" object is identical copy of the "sphere1". For example,
to create 50 spheres aligned on 'x' axis:
There are some restrictions thought. For example, you cannot move a material
object into a grid object. to grid geometric object
Selecting and Modifying
Loading Files
There are many useful scripts shipped with the scripting system. One of the
most useful is the one which allows you to modify geometric objects through
the scripting window.
To load the script file, enter:
"geometrics.h" LOAD
You can now modify geometric objects easily. If you need to do this often,
you can add the above command to your startup script (scripting/rpl/startup.h)
so that it is automatically loaded for you.
Selecting Objects.
|